<?php

/**
 * 合同性质仓库
 * @author wangwx 2015-5-12
 */
namespace common\repositories\myhtsq;
use common\repositories\BaseRepository;
use common\support\StringHelper;
use common\entities\myhtsq\ContractPropertyEntity;
class ContractPropertyRepository extends BaseRepository{

	/**
	 * 构造方法
	 * @param unknown $config (optional)
	 */
	public function __construct($config = [])
	{
		parent::__construct($config);
	}
	
	
	/**
	 * 获取全部合同性质
	 */
	public static function getAllContractProperty() {
		return ContractPropertyEntity::find()->all();
	}

    /**
     * 根据性质id,获取性质名称
     * @param string $propertyId 性质id
     * @return string 性质名称
     */
    public static function getContractSourceByPropertyId($propertyId){
        return ContractPropertyEntity::find()->select('*')->where(['property_id'=>$propertyId])->one();
    }
	
	/**
	 * 根据性质id,获取性质名称
	 * @param string $propertyId 性质id
	 * @return string 性质名称
	 */
	public static function getPropertyNameByPropertyId($propertyId){
		return ContractPropertyEntity::find()->select('property_name')->where(['property_id'=>$propertyId])->scalar();
	}

    /**
     * 获取全部合同性质
     * @return array
     */
    public static function getAllContractPropertyList() {
        return ContractPropertyEntity::find()->asArray()->all();
    }

    /**
     * 根据合同性质名称获取ID
     *
     * @param  $name string 性质名称
     * @return array|null|\yii\db\ActiveRecord
     */
    public static function getPropertyIdByName($name){
        $map['property_name'] = $name;

        $result = ContractPropertyEntity::find()->select('property_id')->where($map)->scalar();
        return $result;
    }
	
}